package com.lai.note.util;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;

import java.util.ArrayList;
import java.util.List;

public class ListAppUtil {

    public static List<PackageInfo> getUserAppList(Context context){
        List<PackageInfo> ret = new ArrayList<PackageInfo>();
        for(PackageInfo packageInfo:context.getPackageManager().getInstalledPackages(0)){
            if(!isSystemApp(packageInfo)){
                ret.add(packageInfo);
            }
        }
        return ret;
    }

    //判断某个应用是否是系统应用
    private static boolean isSystemApp(PackageInfo packageInfo){
        return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
    }

}
